package com.longteng.diamond.service;

import com.longteng.diamond.dao.InterfaceMockDataMapper;
import com.longteng.diamond.domain.InterfaceMockData;
import com.longteng.diamond.po.TablePage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator
 * DATE : 2018/8/6
 * TIME : 21:50
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Component
@Slf4j
public class InterfaceMockDataService {
    @Autowired
    InterfaceMockDataMapper interfaceMockDataMapper;

    /**
     * 获取接口
     *
     * @param interfaceMockData
     * @return interfaceMockData
     */
    public TablePage getInterfaceMockData(InterfaceMockData interfaceMockData) {
        TablePage tablePage = new TablePage();
        try {
            /**通过limit计算返回的数据**/
            List<InterfaceMockData> interfaceMockDataList = interfaceMockDataMapper.getInterfaceMockData(interfaceMockData);
            tablePage.setRows(interfaceMockDataList);
            /**获取当前where条件的所有行数，如果你的where条件不变化的话，每次返回的所有行数都是一样的**/
            long total = interfaceMockDataMapper.queryAllRow(interfaceMockData);
            tablePage.setTotal(total);
            /**interfaceMockDataList 和total 它们的where条件应该是一模一样的**/
        } catch (Exception e) {
            log.error("查询接口列表异常", e);
        }
        return tablePage;
    }

    /**
     * 新增接口
     * @param interfaceMockData
     * @return
     */
    public void addInterfaceMockData(InterfaceMockData interfaceMockData) {
        interfaceMockDataMapper.addInterfaceMockData(interfaceMockData);
    }

    /**
     * 修改接口
     * @param interfaceMockData
     * @return void
     */
    public void updateInterfaceMockData(InterfaceMockData interfaceMockData) {
        interfaceMockDataMapper.updateInterfaceMockData(interfaceMockData);
    }

    /**
     * 根据id获取接口
     * @param interfaceId
     * @return interfaceMockData
     */
    public InterfaceMockData findInterfaceMockDataById(Integer interfaceId) {
        return interfaceMockDataMapper.findInterfaceMockDataById(interfaceId);
    }

    /**
     * 删除接口
     * @param interfaceId
     * @return void
     */
    public void deleteInterfaceMockDataById(Integer interfaceId) {
        interfaceMockDataMapper.deleteInterfaceMockDataById(interfaceId);
    }
}
